package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.MinioUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@AllArgsConstructor
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> add(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String filename = originalFilename == null ? UUID.randomUUID().toString() : UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
//        file.transferTo(new File("E:\\temp\\"+filename));
        String url = MinioUtil.upLoadFile(file, filename);
        return Result.success(url);
    }
}
